<?php
	include_once("DBManager.php");
	
	$aResults = array();
	$variables = array();
	
	$request = strtolower($_GET['input']);

	//creamos el objeto $con a partir de la clase DBManager
   	$con = new DBManager;
	//usamos el metodo conectar para realizar la conexion
	if($con->conectar()==true){
	 	$query = "SELECT * FROM usuarios WHERE tu_username LIKE '$request%' limit 10";
		$result = mysql_query($query);
		while($row = mysql_fetch_array($result))
		{
		  	$aResults[] = array("id" => $row['id'],"value" =>$row['tu_username'],"info" =>$row['tu_username']);
		}  
	}

	header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
	header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // always modified
	header ("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
	header ("Pragma: no-cache"); // HTTP/1.0
	
	if (isset($_REQUEST['json']))
	{
		header("Content-Type: application/json");
	
		echo "{\"results\": [";
		$arr = array();
		for ($i=0;$i<count($aResults);$i++)
		{
			$arr[] = "{\"id\": \"".$aResults[$i]['id']."\", \"value\": \"".$aResults[$i]['value']."\", \"info\": \"\"}";
		}
		echo implode(", ", $arr);
		echo "]}";
	}
	
?>